package com.kayak.kboot.dao;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.ScanResult;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.BinaryClient.LIST_POSITION;

/**
 * @author Internet
 *
 */
@Repository
public class JedisEx  {
	private static Logger log = LoggerFactory.getLogger(JedisEx.class);
	
	@Autowired
	private JedisPool jedisPool;


	/**
	 * 根据操作类型获取连接池
	 *
	 * @param oType
	 *            R:读取缓存数据库 W:操作缓存数据
	 * @return
	 */
	public Jedis getJedis() {
		return jedisPool.getResource();

	}

	/**
	 * 返回关闭数据
	 *
	 * @param Jedis
	 */
	public void returnBrokenResource(Jedis Jedis) {
		try {
			jedisPool.returnBrokenResource(Jedis);
		} catch (Exception e) {
			log.error("returnBrokenResource error:{}", e.getMessage());
		}
	}

	/**
	 * 返回关闭数据
	 *
	 * @param Jedis
	 */
	public void returnResource(Jedis Jedis) {
		try {
			jedisPool.returnResource(Jedis);
		} catch (Exception e) {
			log.error("returnResource error：{}", e.getMessage());
		}
	}


	public void setJedisPool(JedisPool jedisPool) {
		this.jedisPool = jedisPool;
	}



	/**
	 * 存放字符串数据
	 *
	 * @param key
	 *            存储ID
	 * @param value
	 *            数据
	 * @return
	 */
	public String set(String key, String value) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.set(key, value);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	/**
	 * 获取缓存数据
	 *
	 * @param key
	 * @return
	 */
	public String get(String key) {
		return this.get(key, "");
	}

	/**
	 * 获取缓存数据
	 *
	 * @param key
	 * @param defaultValue
	 * @return
	 */
	public String get(String key, String defaultValue) {
		Jedis Jedis = this.getJedis();
		try {
			String value = Jedis.get(key);
			return value == null ? defaultValue : value;
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public String echo(String string) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.echo(string);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public Boolean exists(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.exists(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public String type(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.type(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	/**
	 * 存放字符串数据
	 *
	 * @param key
	 *            存储ID
	 * @param seconds
	 *            时间
	 * @return
	 */
	public Long expire(String key, int seconds) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.expire(key, seconds);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public Long expireAt(String key, long unixTime) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.expireAt(key, unixTime);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public Long ttl(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.ttl(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public Boolean setbit(String key, long offset, boolean value) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.setbit(key, offset, value);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public Boolean setbit(String key, long offset, String value) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.setbit(key, offset, value);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public Boolean getbit(String key, long offset) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.getbit(key, offset);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public Long setrange(String key, long offset, String value) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.setrange(key, offset, value);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public String getrange(String key, long startOffset, long endOffset) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.getrange(key, startOffset, endOffset);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public String getSet(String key, String value) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.getSet(key, value);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public Long setnx(String key, String value) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.setnx(key, value);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	/**
	 * 存放字符串数据(根据我们设定的有效期)
	 *
	 * @param key
	 *            存储ID
	 * @param second
	 *            以秒为单位
	 * @param value
	 *            数据
	 * @return
	 */
	public String setex(String key, int second, String value) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.setex(key, second, value);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public List<String> blpop(String arg) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.blpop(arg);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public List<String> brpop(String arg) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.brpop(arg);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public Long decrBy(String key, long integer) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.decrBy(key, integer);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public Long decr(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.decr(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public Long incrBy(String key, long integer) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.incrBy(key, integer);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public Long incr(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.incr(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public Long append(String key, String value) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.append(key, value);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public String substr(String key, int start, int end) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.substr(key, start, end);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public Long hset(String key, String field, String value) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.hset(key, field, value);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public String hget(String key, String field) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.hget(key, field);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long hsetnx(String key, String field, String value) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.hsetnx(key, field, value);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public String hmset(String key, Map<String, String> hash) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.hmset(key, hash);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public List<String> hmget(String key, String... fields) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.hmget(key, fields);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long hincrBy(String key, String field, long value) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.hincrBy(key, field, value);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Boolean hexists(String key, String field) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.hexists(key, field);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	/**
	 * 删除数据
	 *
	 * @param key
	 *            存储ID
	 * @return
	 */
	public Long del(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.del(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}
	}

	public Long hdel(String key, String... fields) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.hdel(key, fields);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long hlen(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.hlen(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<String> hkeys(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.hkeys(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public List<String> hvals(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.hvals(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Map<String, String> hgetAll(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.hgetAll(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	/**
	 * 
	 * @param key
	 * @param strings
	 * @return
	 */
	public Long rpush(String key, String... strings) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.rpush(key, strings);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	/**
	 * 
	 * @param key
	 * @param strings
	 * @return
	 */
	public Long lpush(String key, String... strings) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.lpush(key, strings);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long lpushx(String key, String... string) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.lpushx(key, string);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long strlen(final String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.strlen(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long move(String key, int dbIndex) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.move(key, dbIndex);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long rpushx(String key, String... string) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.rpushx(key, string);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long persist(final String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.persist(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long llen(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.llen(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public List<String> lrange(String key, long start, long end) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.lrange(key, start, end);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public String ltrim(String key, long start, long end) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.ltrim(key, start, end);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public String lindex(String key, long index) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.lindex(key, index);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public String lset(String key, long index, String value) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.lset(key, index, value);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long lrem(String key, long count, String value) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.lrem(key, count, value);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public String lpop(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.lpop(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public String rpop(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.rpop(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long sadd(String key, String... members) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.sadd(key, members);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<String> smembers(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.smembers(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long srem(String key, String... members) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.srem(key, members);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public String spop(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.spop(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long scard(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.scard(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Boolean sismember(String key, String member) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.sismember(key, member);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public String srandmember(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.srandmember(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long zadd(String key, double score, String member) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zadd(key, score, member);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long zadd(String key, Map<String, Double> scoreMembers) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zadd(key, scoreMembers);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<String> zrange(String key, long start, long end) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrange(key, start, end);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long zrem(String key, String... members) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrem(key, members);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Double zincrby(String key, double score, String member) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zincrby(key, score, member);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long zrank(String key, String member) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrank(key, member);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long zrevrank(String key, String member) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrevrank(key, member);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<String> zrevrange(String key, long start, long end) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrevrange(key, start, end);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<Tuple> zrangeWithScores(String key, long start, long end) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrangeWithScores(key, start, end);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<Tuple> zrevrangeWithScores(String key, long start, long end) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrevrangeWithScores(key, start, end);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long zcard(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zcard(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Double zscore(String key, String member) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zscore(key, member);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public List<String> sort(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.sort(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public List<String> sort(String key, SortingParams sortingParameters) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.sort(key, sortingParameters);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long zcount(String key, double min, double max) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zcount(key, min, max);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long zcount(String key, String min, String max) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zcount(key, min, max);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<String> zrangeByScore(String key, double min, double max) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrangeByScore(key, min, max);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<String> zrevrangeByScore(String key, double max, double min) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrevrangeByScore(key, max, min);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<String> zrangeByScore(String key, double min, double max, int offset, int count) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrangeByScore(key, min, max, offset, count);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<String> zrevrangeByScore(String key, double max, double min, int offset, int count) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrevrangeByScore(key, max, min, offset, count);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrangeByScoreWithScores(key, min, max);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrevrangeByScoreWithScores(key, max, min);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrangeByScoreWithScores(key, min, max, offset, count);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrevrangeByScoreWithScores(key, max, min, offset, count);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<String> zrangeByScore(String key, String min, String max) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrangeByScore(key, min, max);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<String> zrevrangeByScore(String key, String max, String min) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrevrangeByScore(key, max, min);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<String> zrangeByScore(String key, String min, String max, int offset, int count) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrangeByScore(key, min, max, offset, count);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<String> zrevrangeByScore(String key, String max, String min, int offset, int count) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrevrangeByScore(key, max, min, offset, count);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<Tuple> zrangeByScoreWithScores(String key, String min, String max) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrangeByScoreWithScores(key, min, max);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrevrangeByScoreWithScores(key, max, min);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<Tuple> zrangeByScoreWithScores(String key, String min, String max, int offset, int count) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrangeByScoreWithScores(key, min, max, offset, count);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min, int offset, int count) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zrevrangeByScoreWithScores(key, max, min, offset, count);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long zremrangeByRank(String key, long start, long end) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zremrangeByRank(key, start, end);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long zremrangeByScore(String key, double start, double end) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zremrangeByScore(key, start, end);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long zremrangeByScore(String key, String start, String end) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zremrangeByScore(key, start, end);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long linsert(String key, LIST_POSITION where, String pivot, String value) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.linsert(key, where, pivot, value);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long bitcount(final String key) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.bitcount(key);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public Long bitcount(final String key, long start, long end) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.bitcount(key, start, end);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	@Deprecated
	/**
	 * This method is deprecated due to bug (scan cursor should be unsigned
	 * long) And will be removed on next major release
	 * 
	 * @see https://github.com/xetorthio/jedis/issues/531
	 */
	public ScanResult<Entry<String, String>> hscan(String key, int cursor) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.hscan(key, cursor);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	@Deprecated
	/**
	 * This method is deprecated due to bug (scan cursor should be unsigned
	 * long) And will be removed on next major release
	 * 
	 * @see https://github.com/xetorthio/jedis/issues/531
	 */
	public ScanResult<String> sscan(String key, int cursor) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.sscan(key, cursor);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	@Deprecated
	/**
	 * This method is deprecated due to bug (scan cursor should be unsigned
	 * long) And will be removed on next major release
	 * 
	 * @see https://github.com/xetorthio/jedis/issues/531
	 */
	public ScanResult<Tuple> zscan(String key, int cursor) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zscan(key, cursor);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public ScanResult<Entry<String, String>> hscan(String key, final String cursor) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.hscan(key, cursor);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}
	

	public ScanResult<String> sscan(String key, final String cursor) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.sscan(key, cursor);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}

	public ScanResult<Tuple> zscan(String key, final String cursor) {
		Jedis Jedis = this.getJedis();
		try {
			return Jedis.zscan(key, cursor);
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}
	
	
	public List keysValue(String key) {
		Jedis Jedis = this.getJedis();
		try {
			return null;
		} catch (Exception ex) {
			log.error("set error：{}", ex.getMessage());
			returnBrokenResource(Jedis);
			throw ex;
		} finally {
			returnResource(Jedis);
		}

	}
}
